package com.cssw.fyzb.busi.api.live;

import com.cssw.fyzb.core.model.vo.live.CreatePkVo;
import com.cssw.fyzb.busi.service.live.LiveService;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 申请PK直播
 *
 * @author wondream
 */
@Function(description = "创建PK直播", parameters = {
        @Parameter(name = "userId", type = Type.String, description = "用户标识", required = true),
        @Parameter(name = "fromLiveId", type = Type.String, description = "申请连麦直播ID", required = true),
        @Parameter(name = "toLiveId", type = Type.String, description = "被连麦直播ID", required = true)
})
@Component
public class CreateLivePk implements Action {

    @Autowired
    LiveService liveService;

    private static final Logger logger = LoggerFactory.getLogger(CreateLivePk.class);

    @Override
    public Response execute(Request request) throws Exception {
        Long userId = request.getLong("userId");
        Long fromLiveId = request.getLong("fromLiveId");
        Long toLiveId = request.getLong("toLiveId");
        try {
            Long pkId = liveService.addLivePk(userId, fromLiveId, toLiveId);
            CreatePkVo vo = new CreatePkVo();
            vo.setPkId(pkId);
            return Response.success().put("data", vo);
        } catch (Exception e) {
            logger.error("", e);
        }
        return Response.success("操作成功");
    }
}





